<script type="text/javascript">
 $(document).ready(function(){
    $("#mod_id").change(function(){
       var mod_id = $(this).val();
       if(mod_id!=""){
           $.ajax({
	    	   type: "POST",
	    	   url: "<?php echo base_url();?>model/getcategory",
	    	   data: "mod_id="+mod_id,
	    	   success: function(msg){
                    $("#category_td").html(msg);  
	    	   } 
	    	});
       }
    })
    $("#submit").click(function(){
       var str = "";
       var mod_id = $("#mod_id").val();
       var name = $("#name").val();
       var codes = $("#codes").val();
       var complete_id = $("#complete_id").val();
       $("input[name=category_ids[]]").each(function(){
           if($(this).attr("checked")==true){
               str+=$(this).val()+",";
           }
        })
       if(mod_id == ""){
          alert("请选择型号！");
          return false;
       }
       if(str == ""){
          alert("请选择资料种类！");
          return false;
       }
       if(name == ""){
           alert("请输入套别名称！");
           return false;
       }
       if(codes == ""){
           alert("请输入套别序号！");
           return false;
       }

       if(complete_id!=""){
    	   $.ajax({
	    	   type: "POST",
	    	   url: "<?php echo base_url();?>model/complete_edit",
	    	   data: "complete_id="+complete_id+"&mod_id="+mod_id+"&category_ids="+str+"&name="+name+"&codes="+codes,
	    	   success: function(msg){
		    	    alert("操作成功");
	                window.location.href="<?php echo base_url();?>model/complete";
	    	   } 
	    	});
       }else{
	       $.ajax({
	    	   type: "POST",
	    	   url: "<?php echo base_url();?>model/complete_add",
	    	   data: "mod_id="+mod_id+"&category_ids="+str+"&name="+name+"&codes="+codes,
	    	   success: function(msg){
	    		    alert("操作成功");
	                window.location.href="<?php echo base_url();?>model/complete";
	    	   } 
	    	});
       }	
    })
 })
</script>
<div id="center-column">
			<div class="top-bar">
				<a href="<?php echo  base_url();?>model/complete_add" class="button">新增</a>
				<h1>Contents</h1>
				<div class="breadcrumbs"><a href="#">首页</a> /<?php echo anchor('model/complete_add','添加套别资料');?></div>
			</div>
			
		  <div class="table add_table">						
				<table class="listing form" cellpadding="0" cellspacing="0">
				<input type="hidden" id="complete_id" value="<?php if(isset($id)){ echo $id; }?>" />
						 
					<tr>
						<th  colspan="2"  align="center"><?php if(isset($id)){?>编辑成套资料<?php }else{?>新增成套资料<?php }?></th>
					</tr>
					<tr>
						<td class="first""><strong>型号：</strong></td>
						<td class="last"><select name="mod_id" id="mod_id">
						                 <option value="">请选择型号</option> 
						               <?php foreach($mod as $k=>$val){?>
						                 <option value="<?php echo $val->mod_id;?>" <?php if(isset($id)){ if($val->mod_id==$complete->mod_id){?>selected=true <?php }}?>><?php echo $val->name;?></option> 
						               <?php }?>  
						</select></td>
					</tr>
					<tr>
						<td class="first" width="172"><strong>资料种类：</strong></td>
						<td class="last" id="category_td"> 
						  <?php if(isset($id)){ echo $category;}?>
						</td>
					</tr>
					<tr>
						<td class="first""><strong>套别名称：</strong></td>
						<td class="last"><input type="text" class="text" name="name" id="name" value="<?php if(isset($id)){echo $complete->name;}?>" /></td>
					</tr>
					<tr class="bg">
						<td class="first""><strong>套别序号：</strong></td>
						<td class="last"><input type="text" class="text" name="codes" id="codes" value="<?php if(isset($id)){echo $complete->codes;}?>" /></td>
					</tr>
					<tr>
						<td colspan="2" style="text-align:center;"><input type="button" value="提交" class="button" id="submit"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="返回" class="button" onclick="location.href='<?php echo site_url()?>model/complete'" /></td>			
					</tr>
				</table>
	        <p>&nbsp;</p>
		  </div>
		</div>
	</div>
	<div id="footer"></div>
</div>



</body>
</html>
